'use strict';

angular.module('fbdApp.templateModule')

.filter('showTempFilter', function() {

  return function(originRule, originResult) {
    var showResult = {};
    showResult['rule'] = {};
    showResult['template'] = {};
    showResult['rule']['head'] = [];
    showResult['rule']['res'] = [];
    var mainRule = originRule[0].name;
    for (var i = 1; i < originRule.length; i++) {
      var curr = originRule[i];
      if (originRule[i].length == undefined) {
        showResult['rule']['head'].push(originRule[i].name);
      }
    }
    // console.log(mainRule);
    var mainRes = originResult['main'];
    if (mainRes['valid'] == true) {
      // console.log(mainRes[mainRule].length);
      for (var i = 0; i < mainRes[mainRule].length; i++) {
        // console.log(mainRes[mainRule].length);
        // console.log(i);
        // var curr = {};
        var currPage = mainRes[mainRule][i];    //当前第几篇文章
        // console.log(curr);
        // if (curr['valid'] == true) {
        var collection = [];   //用于存储每一篇的数组
        for (var j = 0; j < showResult['rule']['head'].length; j++) {
          var rules = [];   //用于存储每一篇各规则的数组
          var head = showResult['rule']['head'][j];
          var currRule = currPage[head];
          for (var k = 0; k < currRule.length; k++) {
            rules.push(currRule[k].text);
          }
          collection.push(rules);


            // console.log(head);
            // console.log(curr[head]);
            // currRule.push(currPage[head][0]['text']);

            // showResult['rule']['res'].push(curr[head][0]['text']);

        }
        showResult['rule']['res'].push(collection);
        // }
      }


    }

    return showResult;
  };
});